//
//  ViewController.m
//  TableGridDemo
//
//  Created by 吳瀾洲 on 2020/8/21.
//  Copyright © 2020 kingboyrang. All rights reserved.
//

#import "ViewController.h"
#import "SimpleViewController.h"
#import "CustomViewController.h"
#import "NoBorderViewController.h"
@interface ViewController ()<UITableViewDataSource,UITableViewDelegate>
@property (nonatomic,strong) UITableView *tableView;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"table表格";
    
    [self.view addSubview:self.tableView];
    
    
    
    // Do any additional setup after loading the view.
}
- (UITableView *)tableView{
    if (_tableView==nil) {
        CGRect r = self.view.frame;
        r.origin.y = self.navigationController.navigationBar.frame.size.height;
        r.size.height -= r.origin.y;
        _tableView = [[UITableView alloc] initWithFrame:r style:UITableViewStyleGrouped];
        _tableView.dataSource = self;
        _tableView.delegate = self;
        UIView *footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 0)];
        _tableView.tableFooterView = footerView;
    }
    return _tableView;
}
- (void)viewWillLayoutSubviews{
    [super viewWillLayoutSubviews];
    
    CGRect r = self.tableView.frame;
    r.size = self.view.frame.size;
    self.tableView.frame = r;
    
}

#pragma mark - UITableViewDataSource Methods
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;{
    
    return 3;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
   static NSString *cellIdentifier = @"artcellIdentifier";
   UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
   if (cell==nil) {
       cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
      
       
   }
  
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    if(indexPath.row == 0){
        cell.textLabel.text = @"简单表格";
    }else if(indexPath.row == 1){
        cell.textLabel.text = @"自定义表格";
    }else{
        cell.textLabel.text = @"无边框表格";
    }
    
    return cell;
}

#pragma mark - UITableViewDelegate Methods

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row == 0) {
        SimpleViewController *simple = [[SimpleViewController alloc] init];
        [self.navigationController pushViewController:simple animated:YES];
    }else if (indexPath.row == 1){
        CustomViewController *custom = [[CustomViewController alloc] init];
        [self.navigationController pushViewController:custom animated:YES];
    }else{
        NoBorderViewController *noBoder = [[NoBorderViewController alloc] init];
        [self.navigationController pushViewController:noBoder animated:YES];
    }
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 50.0f;
}
@end
